/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package it.nyquistmeteocal.beans;

import it.nyquistmeteocal.boundary.UserManager;
import javax.ejb.EJB;
import javax.faces.application.ConfigurableNavigationHandler;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ComponentSystemEvent;
 
@ManagedBean(name="access")
@SessionScoped
public class AccessDeniedBean {
  
  @EJB
  private UserManager um = new UserManager();
  
  private EditEventBean edb; 
 
  public void isAdmin(ComponentSystemEvent event, String creator){
 
	FacesContext fc = FacesContext.getCurrentInstance();
        
        String LoggedUser = um.getLoggedUser().getEmail();
        System.out.println("###" + LoggedUser + "###" + creator + "###");
 
	if (!LoggedUser.equals(creator)){
 
		ConfigurableNavigationHandler nav 
		   = (ConfigurableNavigationHandler) 
			fc.getApplication().getNavigationHandler();
 
		nav.performNavigation("access-denied");
	}		
  }	
}
